/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.evl.tecinfo.gui;

import java.util.Scanner;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Tecinfo
 */
public class Cadastra_usuario extends javax.swing.JFrame {
    
    int linha = -1;
    int nada = 0;
   

 public static Object ErroParaInt(String conteudo) {
        try{
        int contint = Integer.parseInt(conteudo);
        while (contint <= 0 ){
            JOptionPane.showMessageDialog(null,"DIE POTATO", null,JOptionPane.INFORMATION_MESSAGE);
        }
        
        }catch (Exception e) {
                JOptionPane.showMessageDialog(null,"HUEHUE.",null,JOptionPane.INFORMATION_MESSAGE);
            }
       
        return 0;
    } 
   

    public static String ErroParaString() {
        String teste = "";
        Scanner sc = new Scanner(System.in);
        while (teste.equals("")) {
            teste = sc.nextLine();
            try {
                while (teste.equals("")) {
                    if (teste.equals("") || teste == null) {
                        JOptionPane.showMessageDialog(null,"Não pode deixar em branco",null,JOptionPane.INFORMATION_MESSAGE);
                        teste = sc.nextLine();
                    }


                }

                if (teste.equals("sair")) {
                    int z = Integer.parseInt(teste);
                    z = 1;
                }

                int i = Integer.parseInt(teste);
                if (i <= 0 || i >= 0) {
                    JOptionPane.showMessageDialog(null,"Digite Apenas Letras.",null,JOptionPane.INFORMATION_MESSAGE);
                    teste = "";
                }
            } catch (Exception c) {
                return teste;
            }
        }
        return teste;
    }

    
    
    
    /**
     * Creates new form Cadastra_usuario
     */
    public Cadastra_usuario() {
        initComponents();
    }

    Cadastra_usuario(String text, String text0, int selectedIndex) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        

        bt_cadastrar = new javax.swing.JButton();
        bt_edituser = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        tb_edituser = new javax.swing.JTable();
        bt_limparuser = new javax.swing.JButton();
        bt_salvaruser = new javax.swing.JButton();
        jl_cargo2 = new javax.swing.JLabel();
        ct_usereditname = new javax.swing.JTextField();
        jl_username = new javax.swing.JLabel();
        jla_usercpf = new javax.swing.JLabel();
        cb_usereditform = new javax.swing.JComboBox();
        jl_uservalor = new javax.swing.JLabel();
        cb_usereditarea = new javax.swing.JComboBox();
        cb_usereditcargo = new javax.swing.JComboBox();
        ct_usereditvalor = new javax.swing.JTextField();
        jl_area2 = new javax.swing.JLabel();
        ct_usereditcpf = new javax.swing.JTextField();
        jl_userform = new javax.swing.JLabel();
        bt_cadastrar_usuario = new javax.swing.JButton();

        bt_cadastrar.setText("Cadastrar");
        bt_cadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_cadastrarActionPerformed(evt);
            }
        });

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        bt_edituser.setText("Editar");
        bt_edituser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_edituserActionPerformed(evt);
            }
        });

        tb_edituser.setDragEnabled(true);

        jScrollPane3.setViewportView(tb_edituser);

        bt_limparuser.setText("Limpar");
        bt_limparuser.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                bt_limparuserMouseClicked(evt);
            }
        });
        bt_limparuser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_limparuserActionPerformed(evt);
            }
        });

        bt_salvaruser.setText("Salvar");
        bt_salvaruser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_salvaruserActionPerformed(evt);
            }
        });

        jl_cargo2.setText("Cargo:");

        jl_username.setText("Nome:");

        jla_usercpf.setText("CPF:");

        cb_usereditform.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecionar", "Cheque", "Dept. Bancário", "Dinheiro" }));

        jl_uservalor.setText("Valor da Hora Extra:");

        cb_usereditarea.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecionar", "Ed. Infantil", "Ens. Fundamental I", "Ens. Fundamental II", "Ens. Médio", "Serviço" }));

        cb_usereditcargo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecionar", "Coordenador", "Professor", "Auxiliar" }));

        jl_area2.setText("Área:");

        jl_userform.setText("Forma de Pagamento:");

        bt_cadastrar_usuario.setText("Cadastrar");
        bt_cadastrar_usuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_cadastrar_usuarioActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(bt_cadastrar_usuario, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(bt_limparuser)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(bt_edituser)
                        .addGap(8, 8, 8)
                        .addComponent(bt_salvaruser))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jla_usercpf)
                            .addGap(18, 18, 18)
                            .addComponent(ct_usereditcpf, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jl_cargo2)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(cb_usereditcargo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jl_uservalor)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(ct_usereditvalor))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jl_area2)
                                .addGap(18, 18, 18)
                                .addComponent(cb_usereditarea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jl_userform)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(cb_usereditform, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jl_username)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(ct_usereditname, javax.swing.GroupLayout.PREFERRED_SIZE, 258, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jl_username)
                            .addComponent(ct_usereditname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jla_usercpf)
                            .addComponent(ct_usereditcpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jl_cargo2)
                            .addComponent(cb_usereditcargo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(6, 6, 6)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jl_area2)
                            .addComponent(cb_usereditarea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(17, 17, 17)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jl_uservalor)
                            .addComponent(ct_usereditvalor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jl_userform)
                            .addComponent(cb_usereditform, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(30, 30, 30)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(bt_limparuser)
                            .addComponent(bt_edituser)
                            .addComponent(bt_cadastrar_usuario)
                            .addComponent(bt_salvaruser))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

		pack();
    }// </editor-fold>//GEN-END:initComponents

    private void bt_edituserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_edituserActionPerformed
        // TODO add your handling code here:
        // Editar(linha);
        try{
            linha = tb_edituser.getSelectedRow();
            ct_usereditname.setText((String) tb_edituser.getValueAt(linha, 0));
            ct_usereditcpf.setText((String)tb_edituser.getValueAt(linha,1));
            cb_usereditcargo.setSelectedItem((String)tb_edituser.getValueAt(linha, 2));
            cb_usereditarea.setSelectedItem((String) tb_edituser.getValueAt(linha, 3));
            ct_usereditvalor.setText((String) tb_edituser.getValueAt(linha, 4));
            cb_usereditform.setSelectedItem((String) tb_edituser.getValueAt(linha, 5));

        }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Selecione uma linha");

        }
    }//GEN-LAST:event_bt_edituserActionPerformed

    private void bt_limparuserMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_bt_limparuserMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_bt_limparuserMouseClicked

    private void bt_limparuserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_limparuserActionPerformed
        // TODO add your handling code here:
        ct_usereditname.setText("");
        ct_usereditcpf.setText("");
        cb_usereditarea.setSelectedIndex(0);
        ct_usereditvalor.setText("");
        cb_usereditform.setSelectedIndex(0);
        cb_usereditcargo.setSelectedIndex(0);
    }//GEN-LAST:event_bt_limparuserActionPerformed

    private void bt_salvaruserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_salvaruserActionPerformed
        // TODO add your handling code here:

        if (linha != -1){
            String erros = "";
            /*String err = ErroParaInt (erros);*/
            String num = ct_usereditname.getText();
            
            
            if (ct_usereditname.getText().equals("") || ct_usereditvalor.getText().equals("") || ct_usereditcpf.getText().equals("")){
                JOptionPane.showMessageDialog(null, "Preencha os campos corretamente", null, JOptionPane.ERROR_MESSAGE);

            }/*else if (ct_usereditvalor.getText().equals(erros) || ct_usereditcpf.getText().equals(erros)) {
             * JOptionPane.showMessageDialog(null, "DIED POTATO", null, JOptionPane.ERROR_MESSAGE);
             * 
             * 
             * 
             * }*/else if(cb_usereditcargo.getSelectedIndex() == 0 || cb_usereditarea.getSelectedIndex() == 0 || cb_usereditform.getSelectedIndex() == 0 ) {
                JOptionPane.showMessageDialog(null, "Preencha os campos corretamente", null, JOptionPane.ERROR_MESSAGE);

                
                
            }else{
                // DefaultTableModel dtm = (DefaultTableModel) tb_tabela.getModel();
                //Object[] opcoes = {ct_nome.getText(), ct_endereco.getText(), ct_cpf.getText(), ct_idade.getText(), cb_selecao.getSelectedItem()};
                tb_edituser.setValueAt(ct_usereditname.getText(),linha,0);
                tb_edituser.setValueAt(ct_usereditcpf.getText(),linha,1);
                tb_edituser.setValueAt(cb_usereditcargo.getSelectedItem(),linha,2);
                tb_edituser.setValueAt(cb_usereditarea.getSelectedIndex(),linha,3);
                tb_edituser.setValueAt(ct_usereditvalor.getText(),linha,4);
                tb_edituser.setValueAt(cb_usereditform.getSelectedItem(),linha,5);
                int confirmacao = JOptionPane.showConfirmDialog(null,"Deseja prosseguir com a operação?",null,JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
                if (confirmacao == JOptionPane.YES_OPTION){
                    JOptionPane.showMessageDialog(null,"Atualização feita com sucesso!",null,JOptionPane.INFORMATION_MESSAGE);
                }
                ct_usereditname.setText("");
                ct_usereditcpf.setText("");
                cb_usereditarea.setSelectedIndex(0);
                ct_usereditvalor.setText("");
                cb_usereditform.setSelectedIndex(0);
                cb_usereditcargo.setSelectedIndex(0);

                linha = -1;
                nada = 2;
            }
        }

        if (linha == -1) {

            if(nada == 2) {

            }
            else if (ct_usereditname.getText().equals("") || ct_usereditvalor.getText().equals("") || ct_usereditcpf.getText().equals("")){
                JOptionPane.showMessageDialog(null, "Os campos não podem ficar em branco", null, JOptionPane.ERROR_MESSAGE);

            }else if(cb_usereditcargo.getSelectedIndex() == 0 || cb_usereditarea.getSelectedIndex() == 0 || cb_usereditform.getSelectedIndex() == 0 ) {
                JOptionPane.showMessageDialog(null, "Preencha os campos corretamente", null, JOptionPane.ERROR_MESSAGE);
            }
            else{
                int confirmacao = JOptionPane.showConfirmDialog(null,"Deseja prosseguir com a operação?",null,JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
                if (confirmacao == JOptionPane.YES_OPTION){
                    JOptionPane.showMessageDialog(null,"Paciente cadastrado com sucesso!",null,JOptionPane.INFORMATION_MESSAGE);
                    //JOptionPane.showMessageDialog(null, "Não pode deixar nada em branco!", null, JOptionPane.ICON_PROPERTY);
                    DefaultTableModel dtm = (DefaultTableModel) tb_edituser.getModel();
                    Object[] opcoes = {ct_usereditname.getText(), ct_usereditcpf.getText(), cb_usereditcargo.getSelectedItem(), cb_usereditarea.getSelectedItem(),ct_usereditvalor.getText(), cb_usereditform.getSelectedItem()};
                    dtm.addRow(opcoes);

                    ct_usereditname.setText("");
                    ct_usereditcpf.setText("");
                    cb_usereditarea.setSelectedIndex(0);
                    ct_usereditvalor.setText("");
                    cb_usereditform.setSelectedIndex(0);
                    cb_usereditcargo.setSelectedIndex(0);
                }

            }

        }
    }//GEN-LAST:event_bt_salvaruserActionPerformed

    private void bt_cadastrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_cadastrarActionPerformed
        // TODO add your handling code here:
        
        /*
try{
        if (linha != -1){
            
           String erros = "";
           ErroParaInt (erros);
            if (ct_usereditname.getText().equals("") || ct_usereditvalor.getText().equals("") || ct_usereditcpf.getText().equals("")){
                JOptionPane.showMessageDialog(null, "Preencha os campos corretamente", null, JOptionPane.ERROR_MESSAGE);
       
               }else if (ct_usereditvalor.getText().equals(erros) || ct_usereditcpf.getText().equals(erros)) {

}  
            }else if(cb_usereditcargo.getSelectedIndex() == 0 || cb_usereditarea.getSelectedIndex() == 0 || cb_usereditform.getSelectedIndex() == 0 ) {
                JOptionPane.showMessageDialog(null, "Preencha os campos corretamente", null, JOptionPane.ERROR_MESSAGE);
            
            } else{
                
                // DefaultTableModel dtm = (DefaultTableModel) tb_tabela.getModel();
                //Object[] opcoes = {ct_nome.getText(), ct_endereco.getText(), ct_cpf.getText(), ct_idade.getText(), cb_selecao.getSelectedItem()};
                tb_edituser.setValueAt(ct_usereditname.getText(),linha,0);
                tb_edituser.setValueAt(ct_usereditcpf.getText(),linha,1);
                tb_edituser.setValueAt(cb_usereditcargo.getSelectedItem(),linha,2);
                tb_edituser.setValueAt(cb_usereditarea.getSelectedIndex(),linha,3);
                tb_edituser.setValueAt(ct_usereditvalor.getText(),linha,4);
                tb_edituser.setValueAt(cb_usereditform.getSelectedItem(),linha,5);
                
                int confirmacao = JOptionPane.showConfirmDialog(null,"Deseja prosseguir com a operação?",null,JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
                if (confirmacao == JOptionPane.YES_OPTION){
                    JOptionPane.showMessageDialog(null,"Atualização feita com sucesso!",null,JOptionPane.INFORMATION_MESSAGE);
                }
                ct_usereditname.setText("");
                ct_usereditcpf.setText("");
                cb_usereditarea.setSelectedIndex(0);
                ct_usereditvalor.setText("");
                cb_usereditform.setSelectedIndex(0);
                cb_usereditcargo.setSelectedIndex(0);
                
                linha = -1;
                nada = 2;
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null,"Forneça apenas números naturais.",null,JOptionPane.INFORMATION_MESSAGE);
            
            }

        if (linha == -1) {

            if(nada == 2) {

            }
            else if (ct_usereditname.getText().equals("") || ct_usereditvalor.getText().equals("") || ct_usereditcpf.getText().equals("")){
                JOptionPane.showMessageDialog(null, "Os campos não podem ficar em branco", null, JOptionPane.ERROR_MESSAGE);

            }else if(cb_usereditcargo.getSelectedIndex() == 0 || cb_usereditarea.getSelectedIndex() == 0 || cb_usereditform.getSelectedIndex() == 0 ) {
                JOptionPane.showMessageDialog(null, "Escolha um sexo!", null, JOptionPane.ERROR_MESSAGE);
            }
            else{
                int confirmacao = JOptionPane.showConfirmDialog(null,"Deseja prosseguir com a operação?",null,JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
                if (confirmacao == JOptionPane.YES_OPTION){
                    JOptionPane.showMessageDialog(null,"Paciente cadastrado com sucesso!",null,JOptionPane.INFORMATION_MESSAGE);
                    //JOptionPane.showMessageDialog(null, "Não pode deixar nada em branco!", null, JOptionPane.ICON_PROPERTY);
                    DefaultTableModel dtm = (DefaultTableModel) tb_edituser.getModel();
                    Object[] opcoes = {ct_usereditname.getText(), ct_usereditcpf.getText(), cb_usereditcargo.getSelectedItem(), cb_usereditarea.getSelectedItem(),ct_usereditvalor.getText(), cb_usereditform.getSelectedItem()};
                    dtm.addRow(opcoes);

                ct_usereditname.setText("");
                ct_usereditcpf.setText("");
                cb_usereditarea.setSelectedIndex(0);
                ct_usereditvalor.setText("");
                cb_usereditform.setSelectedIndex(0);
                cb_usereditcargo.setSelectedIndex(0);
                
                }

            }

        }*/
    }//GEN-LAST:event_bt_cadastrarActionPerformed

    private void bt_cadastrar_usuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_cadastrar_usuarioActionPerformed
        // TODO add your handling code here:
        if (linha != -1){
            
            
            if (ct_usereditname.getText().equals("") || ct_usereditvalor.getText().equals("") || ct_usereditcpf.getText().equals("")){
                JOptionPane.showMessageDialog(null, "Preencha os campos corretamente", null, JOptionPane.ERROR_MESSAGE);

            }else if (ct_usereditvalor.getText().equals("") || ct_usereditcpf.getText().equals("")) {
                JOptionPane.showMessageDialog(null, "DIED POTATO", null, JOptionPane.ERROR_MESSAGE);
                
            }else if(cb_usereditcargo.getSelectedIndex() == 0 || cb_usereditarea.getSelectedIndex() == 0 || cb_usereditform.getSelectedIndex() == 0 ) {
                JOptionPane.showMessageDialog(null, "Preencha os campos corretamente", null, JOptionPane.ERROR_MESSAGE);
            
           
            }else{
                // DefaultTableModel dtm = (DefaultTableModel) tb_tabela.getModel();
                //Object[] opcoes = {ct_nome.getText(), ct_endereco.getText(), ct_cpf.getText(), ct_idade.getText(), cb_selecao.getSelectedItem()};
                tb_edituser.setValueAt(ct_usereditname.getText(),linha,0);
                tb_edituser.setValueAt(ct_usereditcpf.getText(),linha,1);
                tb_edituser.setValueAt(cb_usereditcargo.getSelectedItem(),linha,2);
                tb_edituser.setValueAt(cb_usereditarea.getSelectedIndex(),linha,3);
                tb_edituser.setValueAt(ct_usereditvalor.getText(),linha,4);
                tb_edituser.setValueAt(cb_usereditform.getSelectedItem(),linha,5);
                
                int confirmacao = JOptionPane.showConfirmDialog(null,"Deseja prosseguir com a operação?",null,JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
                if (confirmacao == JOptionPane.YES_OPTION){
                    JOptionPane.showMessageDialog(null,"Atualização feita com sucesso!",null,JOptionPane.INFORMATION_MESSAGE);
                }
                ct_usereditname.setText("");
                ct_usereditcpf.setText("");
                cb_usereditarea.setSelectedIndex(0);
                ct_usereditvalor.setText("");
                cb_usereditform.setSelectedIndex(0);
                cb_usereditcargo.setSelectedIndex(0);
                
                linha = -1;
                nada = 2;
            }
        }

        if (linha == -1) {
            /*try {*/
            if(nada == 2) {

            }
            
            String num = ct_usereditcpf.getText();
            ErroParaInt(num);
            
            
            /*String erros = "";
             * ErroParaInt (erros);*/
            if (ct_usereditname.getText().equals("") || ct_usereditvalor.getText().equals("") || ct_usereditcpf.getText().equals("")){
                JOptionPane.showMessageDialog(null, "Preencha os campos corretamente", null, JOptionPane.ERROR_MESSAGE);

            }/*else if (ct_usereditvalor.getText().equals(erros) || ct_usereditcpf.getText().equals(erros)) {
             * JOptionPane.showMessageDialog(null, "DIE POTATO", null, JOptionPane.ERROR_MESSAGE);
             * 
             * }*/else if(cb_usereditcargo.getSelectedIndex() == 0 || cb_usereditarea.getSelectedIndex() == 0 || cb_usereditform.getSelectedIndex() == 0 ) {
                JOptionPane.showMessageDialog(null, "Preencha os campos corretamente", null, JOptionPane.ERROR_MESSAGE);
            
           
            }else{
                int confirmacao = JOptionPane.showConfirmDialog(null,"Deseja prosseguir com a operação?",null,JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
                if (confirmacao == JOptionPane.YES_OPTION){
                    JOptionPane.showMessageDialog(null,"Paciente cadastrado com sucesso!",null,JOptionPane.INFORMATION_MESSAGE);
                    //JOptionPane.showMessageDialog(null, "Não pode deixar nada em branco!", null, JOptionPane.ICON_PROPERTY);
                    DefaultTableModel dtm = (DefaultTableModel) tb_edituser.getModel();
                    Object[] opcoes = {ct_usereditname.getText(), ct_usereditcpf.getText(), cb_usereditcargo.getSelectedItem(), cb_usereditarea.getSelectedItem(),ct_usereditvalor.getText(), cb_usereditform.getSelectedItem()};
                    dtm.addRow(opcoes);

                ct_usereditname.setText("");
                ct_usereditcpf.setText("");
                cb_usereditarea.setSelectedIndex(0);
                ct_usereditvalor.setText("");
                cb_usereditform.setSelectedIndex(0);
                cb_usereditcargo.setSelectedIndex(0);
                
                }

            }

            /*} catch (Exception e) {
             * JOptionPane.showMessageDialog(null,"Forneça apenas números naturais.",null,JOptionPane.INFORMATION_MESSAGE);
             * 
             * }*/
        }
    }//GEN-LAST:event_bt_cadastrar_usuarioActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Cadastra_usuario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Cadastra_usuario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Cadastra_usuario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Cadastra_usuario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Cadastra_usuario().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.JButton bt_cadastrar;
    private javax.swing.JButton bt_cadastrar_usuario;
    public static javax.swing.JButton bt_edituser;
    private javax.swing.JButton bt_limparuser;
    private javax.swing.JButton bt_salvaruser;
    private javax.swing.JComboBox cb_usereditarea;
    private javax.swing.JComboBox cb_usereditcargo;
    private javax.swing.JComboBox cb_usereditform;
    private javax.swing.JTextField ct_usereditcpf;
    private javax.swing.JTextField ct_usereditname;
    private javax.swing.JTextField ct_usereditvalor;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JLabel jl_area2;
    private javax.swing.JLabel jl_cargo2;
    private javax.swing.JLabel jl_userform;
    private javax.swing.JLabel jl_username;
    private javax.swing.JLabel jl_uservalor;
    private javax.swing.JLabel jla_usercpf;
    public static javax.swing.JTable tb_edituser;

    // End of variables declaration            
}
